import 'dart:typed_data';
import 'package:image_gallery_saver_plus/image_gallery_saver_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:dio/dio.dart';

class DownImage {
  static Future<String> saveImage(context, String imagePath) async {
    var status = await Permission.storage.status;
    if (!status.isGranted) {
      //未授予
      Permission.storage.request();
    }

    var response = await Dio()
        .get(imagePath, options: Options(responseType: ResponseType.bytes));
    final result = await ImageGallerySaverPlus.saveImage(
      Uint8List.fromList(response.data),
      quality: 100,
    );
    if (result["isSuccess"]) {
     
      return result["filePath"];
    } else {
      
      return 'error';
    }
  }
}
